package com.hb.back.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hb.back.domain.EduAclRole;
import com.hb.back.domain.EduAclUser;
import com.hb.back.mapper.EduAclRoleMapper;
import com.hb.back.service.EduAclUserService;
import com.hb.back.mapper.EduAclUserMapper;
import com.hb.common.vo.MentVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 */
@Service
public class EduAclUserServiceImpl extends ServiceImpl<EduAclUserMapper, EduAclUser>
    implements EduAclUserService, UserDetailsService {
      @Autowired
      EduAclRoleMapper eduAclRoleMapper;
      @Autowired
      EduAclUserMapper eduAclUserMapper;
     @Override
     public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
      EduAclUser aclUser=this.getOne(new LambdaQueryWrapper<EduAclUser>().eq(EduAclUser::getUsername,username));
      if (aclUser==null){
     throw new UsernameNotFoundException("用户不存在");
      }
      //把用户的roles符值上
         List<EduAclRole> roleList=eduAclRoleMapper.selectPres(aclUser.getId());
        aclUser.setRoles(roleList);
        return aclUser;
    }

    public List<MentVo> getMentByUsername(String name) {
     return eduAclUserMapper.getMenuByUsername(name);
    }
}




